package com.xxz.controller;
import com.xxz.config.LoginHandlerInterceptor;
import com.xxz.config.MyLocaleResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MyMvcController implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
       registry.addViewController("/").setViewName("index");
       registry.addViewController("/index.html").setViewName("index");
       registry.addViewController("/xxz").setViewName("dashboard");
    }
    //国际化操作注册bean
    @Bean
    public LocaleResolver localeResolver() {
        return new MyLocaleResolver();
    }
    @Override  // 重写拦截器方法
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor())
                .addPathPatterns("/**")//拦截所有请求
                .excludePathPatterns("/index.html", "/", "/login", "/css/**", "/js/**", "/img/**");
    }
}